////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////

#ifndef __FONT_H__
#define __FONT_H__

////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////

#define FONT_CH_ENTER				'\n'
#define FONT_CH_SPACE				' '

////////////////////////////////////////////////////////////////////////////////////////////////////
#define A_LEFT				0x00
#define A_HCENTER			0x01
#define A_RIGHT				0x02

#define A_TOP				0x00
#define A_VCENTER			0x10
#define A_BOTTOM			0x20

///////////////////////////////////////////////////////////////////////////////////////////////////
#define MAX_MULTI_LINES		256

#include "Lib2D/Sprite.h"
#include "Strings/Strings.h"
//#include "Application.h"
///////////////////////////////////////////////////////////////////////////////////////////////////
extern unsigned char	__CHARACTERS_MAP[];
extern unsigned char	__CHARACTERS_MAP_FR[];
extern unsigned char	__CHARACTERS_MAP_FR_BIG[];
class CFont : public CSprite
{

public:
	CFont();
	~CFont();

	irr::u32 DrawString( const GX_CHAR* str, int x, int y, int anchor, irr::u8 alpha = MAX_ALPHA, int pos1=0, int pos2=65536, GX_CHAR* pConsoleUnderline = NULL);
	
	void	SplitText( GX_CHAR* str, GX_CHAR* str_out, int width, GX_CHAR separator = ' ' );

	int		GetStringSize(const GX_CHAR* str, int* pW, int* pH, int *widths = NULL);
	int		GetStringSize(const GX_CHAR* str, int* pW, int* pH, int pos1, int pos2, int *widths = NULL);

	//void	GetStringRect( CRect* pRC, const GX_CHAR* str, int x, int y, int anchor );

	void	SetLineSpacing( irr::s16 nLineSpacing );
	irr::s16		GetLineSpacing();

	void	SetCharSpacing( irr::s16 nCharSpacing ) { m_nCharSpacing = nCharSpacing; }
	irr::s16		GetCharSpacing()	{ return m_nCharSpacing; }

	int		GetLineHeight();

	void SetFontName(const char*pName);
private:
	irr::s16		GetCharacterFModule( int nCharCode );
public:
	void ChangeFontColor(GX_CHAR color);
private:
	irr::s32		GetMap( GX_CHAR ch );

	bool IsChinese(GX_CHAR ch);
private:
	irr::s16		m_nLineSpacing;
	irr::s16		m_nCharSpacing;

	irr::s16		_oldPal;

	bool			m_isOnlyEnglish;
public:
	void SetOnlyEnglish(bool b) { m_isOnlyEnglish = b; }

	void SetBigForFranch(bool b );
private:
	bool CheckPunctuationIsRight(GX_CHAR* str);
	bool CheckPunctuationIsRightCN(GX_CHAR* str);

	int FindPunctuationAtWrongPosition(GX_CHAR* str);
	int FindPunctuationAtWrongPositionCN(GX_CHAR* str);

	void ChangePunctuationPosition(GX_CHAR* str, GX_CHAR* str_out);

	void ChangePunctuationPositionCN(GX_CHAR* str, GX_CHAR* str_out);

	void CopyGX_Char(GX_CHAR* str, GX_CHAR* str_out);

	void SplitTextOnly( GX_CHAR* str, GX_CHAR* str_out, int width, GX_CHAR separator);
private:
	bool m_IsBigForFranch;

	irr::core::stringc m_fontName;
};

#endif //__FONT_H__

////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
